define(function() {

    return {
        go: function() {
            $loading();
            FB.api('me/friends', {fields: 'birthday,name'}, $.proxy(this.render, this));
        },
        render: function(res) {
            var today = moment().valueOf();
            $.each(res.data, function() {
                this.ts = 0;
                
                if(this.birthday) {
                    this.moment = moment(moment(this.birthday).format('MM/DD')).year(2012);
                    this.ts = this.moment.valueOf();
                }
            });
            var birthdays = res.data.sort(function(a,b) {
                return (a.ts - b.ts);
            });
            birthdays = $.grep(birthdays, function(n) {
                if(n.ts == 0) { return false; }
                if(n.ts < today) { return false; }
                return true;
            }).slice(0,25);
            
            $.each(birthdays, function() {
                this.ago = this.moment.fromNow();
                this.month = this.moment.format('MMMM').toUpperCase();
                this.date = this.moment.date();
            });
            Template('events', {events: birthdays}, function(html) {
                $content.html(html);
            });
        }
    };
});